import Vue from 'vue'
import App from './App.vue'

import router from './router/index'

// 引入vuex
import store from '@/store'

router.beforeEach((to,from,next)=>{
  store.commit('getToken')
  const token = store.state.user.token
  if(!token && to.name !== 'login'){
    next({name:"login"})
  }else if(token && to.name == 'login'){
    next({name:'home'})
  }else{
    next()
  }
})

// 引入elementUI
import '@/utils/element.js'

Vue.config.productionTip = false


// 初始化样式
import '@/assets/less/index.less'

// 组件传值事件中心线
import '@/utils/eventBus.js'

// 引入mockjs
import '@/api/mock.js'


new Vue({
  router,
  store,
  created(){
    store.commit('addMenu',router)
  },
  render: h => h(App),
}).$mount('#app')
